home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue70 / CLXAndQT / QtCopyU.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2001-03-28  |  1.8 KB  |  89 lines

  1. unit QtCopyU;
  2.  
  3. {$ifdef Ver90} { Delphi 2.0x }
  4.   {$define DelphiLessThan3}
  5. {$endif}
  6.  
  7. interface
  8.  
  9. uses
  10.   SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
  11.  
  12. type
  13.   TFoo = class
  14.   public
  15.     procedure ShowInfo(const Info: String);
  16.   end;
  17.  
  18.   TForm1 = class(TForm)
  19.     Button1: TButton;
  20.     Button2: TButton;
  21.     Button3: TButton;
  22.     procedure Button1Click(Sender: TObject);
  23.     procedure Button2Click(Sender: TObject);
  24.     procedure Button3Click(Sender: TObject);
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30.   Foo: TFoo;
  31.   TFoo_Create: function (ClassRef: TClass; Construct: Boolean): TFoo;
  32.   TFoo_Destroy: procedure (Handle: TFoo; Destroy: Boolean);
  33.   TFoo_Free: procedure (Handle: TFoo);
  34.   TFoo_ShowInfo: procedure (Handle: TFoo; const Info: String);
  35.  
  36. implementation
  37.  
  38. {$R *.DFM}
  39.  
  40. {$ifdef DelphiLessThan3}
  41. procedure ShowMessageFmt(const Msg: string; Params: array of const);
  42. begin
  43.   ShowMessage(Format(Msg, Params));
  44. end;
  45. {$endif}
  46.  
  47. { TFoo }
  48.  
  49. procedure TFoo.ShowInfo(const Info: String);
  50. begin
  51.   ShowMessageFmt('%s: %s', [ClassName, Info])
  52. end;
  53.  
  54. procedure TForm1.Button1Click(Sender: TObject);
  55. var
  56.   Foo: TFoo;
  57. begin
  58.   Foo := TFoo.Create;
  59.   Foo.ShowInfo('Called through a normal method');
  60.   Foo.Free;
  61. end;
  62.  
  63. procedure TForm1.Button2Click(Sender: TObject);
  64. var
  65.   Foo: TFoo;
  66. begin
  67.   Foo := TFoo.Create;
  68.   TFoo_ShowInfo(Foo, 'Called through a function pointer');
  69.   Foo.Free;
  70. end;
  71.  
  72. procedure TForm1.Button3Click(Sender: TObject);
  73. var
  74.   Foo: TFoo;
  75. begin
  76.   Foo := TFoo_Create(TFoo, True);
  77.   TFoo_ShowInfo(Foo, 'Called through a function pointer');
  78.   //TFoo_Free(Foo);
  79.   TFoo_Destroy(Foo, True)
  80. end;
  81.  
  82. initialization
  83.   //Set up procedural variables...
  84.   TFoo_Create := @TFoo.Create;
  85.   TFoo_Free := @TFoo.Free;
  86.   TFoo_Destroy := @TFoo.Destroy;
  87.   TFoo_ShowInfo := @TFoo.ShowInfo;
  88. end.
  89.